<template>
  <div class="login-container">
    <div class="login">
      <h2>信贷管理系统</h2>
      <el-form
        :model="loginForm"
        :rules="rules"
        ref="loginForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="account">
          <el-input v-model="loginForm.account" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            v-model="loginForm.password"
            type="password"
            show-password
          />
        </el-form-item>
        
          <el-button type="primary" @click="submitForm('loginForm')"
            >登录</el-button
          >
      
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    return {
      loginForm: {
        account: "admin",
        password: "approve123456.",
      },
      rules: {
        account: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 10, message: "长度在 3 到 10 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 6,
            max: 18,
            message: "长度在 6 到 18 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    submitForm(fromName) {
      this.$refs[fromName].validate((valid) => {
        if (valid) {
          this.$store.dispatch("loginActions", this.loginForm)
          .then((res) => {
            if(res== 20000){ 
              this.$router.push("/home");
            }
          }).catch(err=>{
            console.log(err);
          });
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.login-container {
  width: 100%;
  height: 100%;
  background: url("@/assets/img/loginbg.jpg") center center no-repeat;
  .login {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    margin: 0 auto;
    background: #fff;
    width: 30%;
    padding: 20px;
    h2 {
      text-align: center;
      margin-bottom: 40px;
    }
    .el-button {
      width: 100%;
    }
    // :deep(.el-form-item__content) {
    //   margin-left: 0px !important;
    // }
    .el-input__inner {
      background-color: #e5e5e5;
    }
    .el-input__prefix,
    .el-input__suffix {
      color: #606266;
    }
  }
}
</style>